{include file="common/head"/}
<style>
    .padding{
        padding-left: 120px;
        box-sizing: border-box;
    }
</style>
<div style="margin: 15px;" class="fadeInUp animated">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>录入新闻栏目</legend>
    </fieldset>
    <div style="width: 100%;margin: 0 auto">
        <form class="layui-form layui-form-pane margin">
            <input type="hidden" id="id" name="id" value="{$info.id}">
            <div class="layui-form-item">
                <label class="layui-form-label">新闻栏目：</label>
                <div class="layui-input-4">
                    <select  name="cate_id" id="cate_id"  lay-search class="layui-input" style="font-size: 15px">
                        {foreach name="cate_list" item="item" }
                        <option value="{$item.id}"  {if condition="$info.cate_id eq $item.id"} selected{/if}>{$item.cate_name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新闻标题：</label>
                <div class="layui-input-4">
                    <input type="text" name="title" lay-verify="required" id="title" value="{$info.title}" placeholder="{:lang('pleaseEnter')}新闻标题" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新闻摘要：</label>
                <div class="layui-input-4">
                    <input type="text" name="abstract" id="abstract" value="{$info.abstract}" placeholder="{:lang('pleaseEnter')}新闻摘要" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">作者：</label>
                <div class="layui-input-4">
                    <input type="text" name="author" lay-verify="required" id="author" maxlength="11" value="{$info.author}" placeholder="{:lang('pleaseEnter')}作者" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">编辑：</label>
                <div class="layui-input-4">
                    <input type="text" name="editor" lay-verify="required"  id="editor" maxlength="11" value="{$info.editor}" placeholder="{:lang('pleaseEnter')}编辑" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label width-150">图片记录：</label>
                <input type="hidden" name="event_image" id="event_image" value="{$info.event_image}">
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-primary" id="adBtn"><i class="icon icon-upload3"></i>点击上传</button>
                        <div class="layui-upload-list" id="adPicList">
                            <img class="layui-upload-img" id="brandPic" src="{$info.event_image}">
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">内容：</label>
                <script id="container"  style="margin-left: 110px;width: 1200px;height: 400px;" name="content" type="text/plain">{$info['content']|raw}</script></div>
            <div class="layui-form-item padding">
                <button type="button" class="layui-btn " lay-submit="" lay-filter="add">立即提交</button>
                <a href="{:url('News/newsList')}" class="layui-btn layui-btn-primary">返回</a>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script><script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
{include file="common/foot"/}
<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>
<script>
    layui.use(['form','jquery', 'layer','upload'], function () {
        var form = layui.form,layer = layui.layer,upload=layui.upload;$= layui.jquery;

        // 监听常规提交
        form.on('submit(add)', function (data) {
            var loading = layer.load();
            data.field.cate_name = $("#cate_id option:selected").html();

            // 提交到方法 默认为本身
            $.post("{:url('newsEdit')}",data.field,function(res){
                layer.close(loading);
                if(res.code == 0){
                    layer.msg(res.msg,{time:1000,icon:1});
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
            return false;
        });
        //事件图片上传
        var uploadInst = upload.render({
            elem: '#adBtn'
            ,url: '{:url("UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#brandPic').attr('src', result); //图片链接（base64）
                });
            },
            done: function(res){
                if(res.code>0){
                    $('#event_image').val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>
</html>